package services

import (
	"longmen/server/internal/rpc/tencentim/messages"
	"longmen/server/internal/services/nami/services/sports/basketball/bbcache"
	"longmen/server/internal/services/nami/services/sports/football/fbcache"
	"longmen/server/pkg/common/api_models"
)

func (s *Service) GetMatchTextService(r *api_models.GetTextLiveReq) []messages.TextLiveStruct {
	//startId := r.LastId - r.Size - 1
	//if startId < 1 {
	//	startId = 1
	//}
	//sort := elastic.NewFieldSort("create_time").Order(true)
	//result, err := global.GetEs().
	//	Search(fmt.Sprint(messages.MatchLiveConst, "_", messages.TextConst, "_", strconv.Itoa(r.RoomId))).
	//	From(startId).Size(r.Size).SortBy(sort).
	//	Do(context.Background())
	//if err != nil {
	//	return nil, err
	//}
	//
	//for _, v := range result.Hits.Hits {
	//	var tl messages.TextLiveStruct
	//	err = json.Unmarshal(v.Source, &tl)
	//	tls = append(tls, tl)
	//}

	var cache []messages.TextLiveStruct

	cache = bbcache.NewTextLiveCache().SearchByEs(r.RoomId, r.Size)
	if len(cache) > 0 {
		return cache
	}
	cache = fbcache.NewTextLiveCache().SearchByEs(r.RoomId, r.Size)
	return cache
}
